package com.aj.service.impl;


import com.aj.entity.Article;
import com.aj.mapper.ArticleMapper;
import com.aj.service.ArticleService;
import com.aj.util.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aj
 * @since 2020-08-03
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

	@Autowired
	ArticleMapper am;
	@Override
	public Result getArticleList() {
		// TODO Auto-generated method stub
		try {
			return new Result(true,"成功辽",200,am.getList());
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return new Result(false,"失败辽，八成参数写错",500,null);
		}
		
	}
	@Override
	public Result getArticleListByTag(long tid) {
		// TODO Auto-generated method stub
		try {
			return new Result(true,"成功辽",200,am.getListByTag(tid));
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return new Result(false,"失败辽，八成参数写错",500,null);
		}
	}
	@Override
	public Result search(String keyword) {
		// TODO Auto-generated method stub
		try {
			return new Result(true,"成功辽",200,am.search(keyword));
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return new Result(false,"失败辽，八成参数写错",500,null);
		}
		
	}
	@Override
	public Result addArticle(Article a) {
		// TODO Auto-generated method stub
		try {
//			System.out.println(a.title+" "+a.text);
			am.addArticle(a);
			return new Result(true,"成功辽",200,null);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return new Result(false,"失败辽",500,null);
		}
	}
	@Override
	public Result updateArticle(Article a) {
		// TODO Auto-generated method stub
		try {
//			System.out.println(a.title+" "+a.text);
			am.updateArticle(a);
			return new Result(true,"成功辽",200,null);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return new Result(false,"失败辽",500,null);
		}
	}
	@Override
	public Result deleteArticle(Article a) {
		// TODO Auto-generated method stub
		try {
//			System.out.println(a.title+" "+a.text);
			am.deleteById(a.getAid());
			return new Result(true,"成功辽",200,null);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return new Result(false,"失败辽",500,null);
		}
	}
	



}
